#include<bits/stdc++.h>
using namespace std;
int T,n,m,s,t,u,v,tot,h[2009],d[2009],nxt[4000009],ver[4000009];
int main(){
    freopen("oi.in","r",stdin);
    freopen("oi.out","w",stdout);
    scanf("%d%d",&n,&T);
    while(T--){
        scanf("%d%d",&n,&m);
        scanf("%d%d",&s,&t);
        for(int i=1;i<=n;i++)h[i]=0,d[i]=0x3f3f3f3f;
        tot=0;
        for(int i=1;i<m;i++){
            scanf("%d%d",&u,&v);
            tot++;
            nxt[tot]=h[u];
            ver[tot]=v;
            h[u]=tot;
            tot++;
            nxt[tot]=h[v];
            ver[tot]=u;
            h[v]=tot;
        }
        queue<int> q;
        d[s]=0;
        q.push(s);
        while(!q.empty()){
            u=q.front();
            q.pop();
            if(u==t)break;
            for(int i=h[u];i;i=nxt[i]){
                if(d[ver[i]]>d[u]+1){
                    d[ver[i]]=d[u]+1;
                    q.push(ver[i]);
                }
            }
        }
        printf("%d %d\n",-d[t]-m+1,m);
    }
    return 0;
}
